package com.verisette.ncos.persistence.dao;

import java.util.List;

import org.apache.log4j.Logger;
import org.corp.agi.persistence.dao.CommonDAOImpl;
import org.jfree.util.Log;

import com.verisette.ncos.persistence.domain.MasterTemplate;
import com.verisette.ncos.persistence.domain.MasterUserProfile;

public class CardDAOImpl extends CommonDAOImpl implements CardDAO {
	
	Logger log = Logger.getLogger(CardDAOImpl.class);
	
	@Override
	public List<MasterTemplate> inquiryMasterTemplate() {
		// TODO Auto-generated method stub
		List<MasterTemplate> listMasterTemplate=null;
		try{
			listMasterTemplate = (List<MasterTemplate>)findAll(MasterTemplate.class);
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return listMasterTemplate;
	}

	public List<MasterTemplate> inquiryMasterTemplateByUspId(MasterUserProfile user) {
		// TODO Auto-generated method stub
		List<MasterTemplate> listMasterTemplate=null;
		try{
			if(log.isDebugEnabled()) log.debug("params:{'uspId':'" + user.getUspId()+"'}");
			StringBuilder sbf = new StringBuilder();
			sbf.append("SELECT mtp.* ");
			sbf.append("FROM   master_user_profile usp ");
			sbf.append("       INNER JOIN dbo.master_template_group_to_usp mtgusp ");
			sbf.append("               ON usp.usp_id = mtgusp.usp_id ");
			sbf.append("       INNER JOIN dbo.master_template_group mtg ");
			sbf.append("               ON mtg.mtg_id = mtgusp.mtg_id ");
			sbf.append("       INNER JOIN dbo.master_template_group_to_mtp mtgmtp ");
			sbf.append("               ON mtg.mtg_id = mtgmtp.mtg_id ");
			sbf.append("       INNER JOIN dbo.master_template mtp ");
			sbf.append("               ON mtp.mtp_id = mtgmtp.mtp_id ");
			sbf.append("WHERE  usp.usp_id = ? ");
			
			listMasterTemplate = (List<MasterTemplate>)nativeQuery(sbf.toString(), MasterTemplate.class, user.getUspId());
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return listMasterTemplate;
	}

	@Override
	public MasterTemplate findMasterTemplateByID(int id) throws Exception 
	{
		return (MasterTemplate) findById(MasterTemplate.class, id);
	}
}
